#ifndef ACAPELLA_SYNCHRONIZE_SCOPED_LOCK_HPP
#define ACAPELLA_SYNCHRONIZE_SCOPED_LOCK_HPP

namespace acapella
{
namespace synchronize
{
	
template<typename LockType>
class scoped_spin_lock
{
public:
	explicit scoped_spin_lock(LockType& lock)
		:lock_(lock)
	{
		lock_.lock();
	}

	~scoped_spin_lock()
	{
		lock_.unlock();
	}

private:
	LockType& lock_;

	scoped_spin_lock(const scoped_spin_lock  & );
	scoped_spin_lock & operator=(const scoped_spin_lock & );
};

template<typename LockType>
class scoped_mutex_cond
{
public:
	explicit scoped_mutex_cond(LockType& lock)
		:lock_(lock)
	{
		lock_.wait();
	}

	~scoped_mutex_cond()
	{
	}

private:
	LockType& lock_;

	scoped_mutex_cond(const scoped_mutex_cond  & );
	scoped_mutex_cond & operator=(const scoped_mutex_cond & );
};


template<typename LockType>
class scoped_read_lock
{
public:
	explicit scoped_read_lock(LockType& lock)
		:lock_(lock)
	{
		lock_.read_lock();
	}

	~scoped_read_lock()
	{
		lock_.read_unlock();
	}

private:
	LockType& lock_;

	scoped_read_lock(const scoped_read_lock  & );
	scoped_read_lock & operator=(const scoped_read_lock & );
};

template<typename LockType>
class scoped_write_lock
{
public:
	explicit scoped_write_lock(LockType& lock)
		:lock_(lock)
	{
		lock_.write_lock();
	}

	~scoped_write_lock()
	{
		lock_.write_unlock();
	}

private:
	LockType& lock_;

	scoped_write_lock(const scoped_write_lock  & );
	scoped_write_lock & operator=(const scoped_write_lock & );
};

}
}

#endif

